package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistdx;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistdx.vo.DpEastListDxPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistdx.vo.DpEastListDxRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistdx.vo.DpEastListDxSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpEastListDxDO;
import cn.iocoder.yudao.module.erp.service.dpeast.DpEastListDxService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - 东线口岸仓东线清单")
@RestController
@RequestMapping("/erp/dp-east-list-dx")
@Validated
public class DpEastListDxController {

    @Resource
    private DpEastListDxService dpEastListDxService;

    @PostMapping("/create")
    @Operation(summary = "创建东线口岸仓东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:create')")
    public CommonResult<Long> createDpEastListDx(@Valid @RequestBody DpEastListDxSaveReqVO createReqVO) {
        return success(dpEastListDxService.createDpEastListDx(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新东线口岸仓东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:update')")
    public CommonResult<Boolean> updateDpEastListDx(@Valid @RequestBody DpEastListDxSaveReqVO updateReqVO) {
        dpEastListDxService.updateDpEastListDx(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除东线口岸仓东线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:delete')")
    public CommonResult<Boolean> deleteDpEastListDx(@RequestParam("id") Long id) {
        dpEastListDxService.deleteDpEastListDx(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得东线口岸仓东线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:query')")
    public CommonResult<DpEastListDxRespVO> getDpEastListDx(@RequestParam("id") Long id) {
        DpEastListDxDO dpEastListDx = dpEastListDxService.getDpEastListDx(id);
        return success(BeanUtils.toBean(dpEastListDx, DpEastListDxRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得东线口岸仓东线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:query')")
    public CommonResult<PageResult<DpEastListDxRespVO>> getDpEastListDxPage(@Valid DpEastListDxPageReqVO pageReqVO) {
        PageResult<DpEastListDxDO> pageResult = dpEastListDxService.getDpEastListDxPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpEastListDxRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出东线口岸仓东线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-dx:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpEastListDxExcel(@Valid DpEastListDxPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpEastListDxDO> list = dpEastListDxService.getDpEastListDxPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "东线口岸仓东线清单.xls", "数据", DpEastListDxRespVO.class,
                        BeanUtils.toBean(list, DpEastListDxRespVO.class));
    }

}